#include <algorithm>
#include <cstddef>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <ostream>
#include <sstream>
#include <string>

#define lld long long // long long 的printf 占位符是lld
#define ENDL '\n'     // 将 endl 替换为 \n 取消缓冲区

const long long MAX_ = 1e9;

using std::cin;
using std::cout;
using std::endl;
using std::min;
using std::string;
const int MOD = 1e9 + 7;

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int T;
  cin >> T;

  int dist[26][26];
  for (int i = 0; i < 26; ++i) {
    for (int j = 0; j < 26; ++j) {
      int d = abs(i - j);
      dist[i][j] = min(d, 26 - d);
    }
  }

  while (T--) {
    string t, c;
    cin >> t >> c;
    int n = t.size();
    int res = 1e9;

    for (int s = 0; s < n; ++s) {
      int ops = min(s, n - s);
      if (ops >= res)
        continue;

      int cnt = 0;
      for (int i = 0; i < n && cnt < res - ops; ++i) {
        char a = t[(s + i) % n];
        char b = c[i];
        cnt += dist[a - 'a'][b - 'a'];
      }
      res = min(res, ops + cnt);
    }

    cout << res << '\n';
  }

  return 0;
}